home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / GDIDIB.PAK / COLORDLG.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  261 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:    colordlg.c
  9. //
  10. //  PURPOSE:   Displays the "Color" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdColor        - Displays the "Color" dialog box
  14. //    Color           - Processes messages for "Color" dialog box.
  15. //    MsgColorInit    - To initialize the color box with version info
  16. //                      from resources.
  17. //    MsgColorCommand - Process WM_COMMAND message sent to the color box.
  18. //    CmdColorOK      - Free the color box and related data. Do OK processing.
  19. //    CmdColorCancel  - Free the color box and related data. Do Cancel
  20. //                      processing.
  21. //    CmdColorPalCtrl - Handles notifications from the PalCtrl.
  22. //
  23. //  COMMENTS:
  24. //
  25. //
  26.  
  27. #include <windows.h>            // required for all Windows applications
  28. #include <windowsx.h>
  29. #include "globals.h"            // prototypes specific to this application
  30. #include "colordlg.h"
  31.  
  32. LRESULT MsgColorInit(HWND, UINT, WPARAM, LPARAM);
  33. LRESULT MsgColorCommand(HWND, UINT, WPARAM, LPARAM);
  34. LRESULT CmdColorOK(HWND, WORD, WORD, HWND);
  35. LRESULT CmdColorCancel(HWND, WORD, WORD, HWND);
  36. LRESULT CmdColorPalCtrl(HWND, WORD, WORD, HWND);
  37.  
  38. // Color dialog message table definition.
  39. MSD rgmsdColor[] =
  40. {
  41.     {WM_COMMAND,    MsgColorCommand},
  42.     {WM_INITDIALOG, MsgColorInit}
  43. };
  44.  
  45. MSDI msdiColor =
  46. {
  47.     sizeof(rgmsdColor) / sizeof(MSD),
  48.     rgmsdColor,
  49.     edwpNone
  50. };
  51.  
  52. // Color dialog command table definition.
  53. CMD rgcmdColor[] =
  54. {
  55.     {IDOK,        CmdColorOK},
  56.     {IDCANCEL,    CmdColorCancel},
  57.  
  58.     // PalCtrl notifications
  59.     {IDD_PALCTRL, CmdColorPalCtrl}
  60. };
  61.  
  62. CMDI cmdiColor =
  63. {
  64.     sizeof(rgcmdColor) / sizeof(CMD),
  65.     rgcmdColor,
  66.     edwpNone
  67. };
  68.  
  69. // Module specific "globals"  Used when a variable needs to be
  70. // accessed in more than on handler function.
  71.  
  72.  
  73. //
  74. //  FUNCTION: Color(HWND, UINT, WPARAM, LPARAM)
  75. //
  76. //  PURPOSE:  Processes messages for "Color" dialog box.
  77. //
  78. //  PARAMETERS:
  79. //    hdlg - window handle of the dialog box
  80. //    wMessage - type of message
  81. //    wparam - message-specific information
  82. //    lparam - message-specific information
  83. //
  84. //  RETURN VALUE:
  85. //    TRUE - message handled
  86. //    FALSE - message not handled
  87. //
  88. //  COMMENTS:
  89. //
  90. //     Display version information from the version section of the
  91. //     application resource.
  92. //
  93. //     Wait for user to click on "Ok" button, then close the dialog box.
  94. //
  95.  
  96. LRESULT CALLBACK Color(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  97. {
  98.     return DispMessage(&msdiColor, hdlg, uMessage, wparam, lparam);
  99. }
  100.  
  101.  
  102. //
  103. //  FUNCTION: MsgColorInit(HWND, UINT, WPARAM, LPARAM)
  104. //
  105. //  PURPOSE: To initialize the Color box with version info from resources.
  106. //
  107. //  PARAMETERS:
  108. //    hwnd - The window handing the message.
  109. //    uMessage - The message number. (unused).
  110. //    wparam - Message specific data (unused).
  111. //    lparam - Message specific data (unused).
  112. //
  113. //  RETURN VALUE:
  114. //    Return FALSE (when calling SetFocus processing WM_INITDIALOG)
  115. //
  116. //  COMMENTS:
  117. //
  118.  
  119. #pragma argsused
  120. LRESULT MsgColorInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  121. {
  122.     // Center the dialog over the application window
  123.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  124.  
  125.     // give the PalCtrl focus
  126.     SetFocus(GetDlgItem(hdlg, IDD_PALCTRL));
  127.  
  128.     // Set color selection in PalCtrl, LPARAM contains the desired index
  129.     SendDlgItemMessage(hdlg, IDD_PALCTRL, PCM_SETCURSEL, wparam, lparam);
  130.  
  131.     return FALSE;
  132. }
  133.  
  134. //
  135. //  FUNCTION: MsgColorCommand(HWND, UINT, WPARAM, LPARAM)
  136. //
  137. //  PURPOSE: Process WM_COMMAND message sent to the Color box.
  138. //
  139. //  PARAMETERS:
  140. //    hwnd - The window handing the message.
  141. //    uMessage - The message number. (unused).
  142. //    wparam - Message specific data (unused).
  143. //    lparam - Message specific data (unused).
  144. //
  145. //  RETURN VALUE:
  146. //    Always returns 0 - message handled.
  147. //
  148. //  COMMENTS:
  149. //    Uses this DipsCommand function defined in wndproc.c combined
  150. //    with the cmdiColor structure defined in this file to handle
  151. //    the command messages for the Color dialog box.
  152. //
  153.  
  154. #pragma argsused
  155. LRESULT MsgColorCommand(HWND   hwnd,
  156.                                 UINT   uMessage,
  157.                                 WPARAM wparam,
  158.                                 LPARAM lparam)
  159. {
  160.      return DispCommand(&cmdiColor, hwnd, wparam, lparam);
  161. }
  162.  
  163.  
  164. //
  165. //  FUNCTION: CmdColorOK(HWND, WORD, HWND)
  166. //
  167. //  PURPOSE: Free the Color box and related data.
  168. //
  169. //  PARAMETERS:
  170. //    hwnd - The window handling the command.
  171. //    wCommand - The command to be handled (unused).
  172. //    hwndCtrl - NULL (unused).
  173. //
  174. //  RETURN VALUE:
  175. //    Always returns TRUE.
  176. //
  177. //  COMMENTS:
  178. //    Calls EndDialog to finish the dialog session.
  179. //
  180.  
  181. #pragma argsused
  182. LRESULT CmdColorOK(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  183. {
  184.      // Get the current color selection
  185.      SendMessage(hwndCtrl, PCM_GETCURSEL, (WPARAM)NULL, (LPARAM)&palinfo);
  186.  
  187.      EndDialog(hdlg, TRUE);          // Exit the dialog
  188.     return TRUE;
  189. }
  190.  
  191.  
  192. //
  193. //  FUNCTION: CmdColorCancel(HWND, WORD, HWND)
  194. //
  195. //  PURPOSE: Free the Color box and related data.
  196. //
  197. //  PARAMETERS:
  198. //    hwnd - The window handling the command.
  199. //    wCommand - The command to be handled (unused).
  200. //    hwndCtrl - NULL (unused).
  201. //
  202. //  RETURN VALUE:
  203. //    Always returns TRUE.
  204. //
  205. //  COMMENTS:
  206. //    Calls EndDialog to finish the dialog session.
  207. //
  208.  
  209. #pragma argsused
  210. LRESULT CmdColorCancel(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  211. {
  212.      // user cancelled, return -1 in index field of palinfo
  213.      palinfo.index = -1;
  214.      palinfo.red = palinfo.green = palinfo.blue = 0;
  215.  
  216.     EndDialog(hdlg, TRUE);          // Exit the dialog
  217.     return TRUE;
  218. }
  219.  
  220.  
  221. //
  222. //  FUNCTION: CmdColorPalCtrl(HWND, WORD, HWND)
  223. //
  224. //  PURPOSE:
  225. //
  226. //  PARAMETERS:
  227. //    hwnd - The window handling the command.
  228. //    wCommand - The command to be handled (unused).
  229. //    hwndCtrl - NULL (unused).
  230. //
  231. //  RETURN VALUE:
  232. //    Always returns TRUE.
  233. //
  234. //  COMMENTS:
  235. //
  236.  
  237. #pragma argsused
  238. LRESULT CmdColorPalCtrl(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  239. {
  240.      switch (wNotify)
  241.      {
  242.           case PCN_CHANGE:
  243.                 {
  244.                      // Get the current color selection
  245.                 SendMessage(hwndCtrl, PCM_GETCURSEL, (WPARAM)NULL, (LPARAM)&palinfo);
  246.  
  247.                 // Update index and RGB edit controls
  248.                 SetDlgItemInt(hdlg, IDD_INDEX, palinfo.index, FALSE);
  249.                 SetDlgItemInt(hdlg, IDD_RED, palinfo.red, FALSE);
  250.                 SetDlgItemInt(hdlg, IDD_GREEN, palinfo.green, FALSE);
  251.                 SetDlgItemInt(hdlg, IDD_BLUE, palinfo.blue, FALSE);
  252.             }
  253.             break;
  254.  
  255.         default:
  256.                 break;
  257.     }
  258.  
  259.     return TRUE;
  260. }
  261.